""" chasePlayer.py Sets the target as the players position so the monster
will chase the player.
"""
distanceToPlayer = Vector3.Distance(thisMonster.Position, level.TPC.Position)

if distanceToPlayer < 225:
    if thisMonster.CurrentAnim != "attack":
        thisMonster.CurrentAnim = "attack"
    if thisMonster.CurrentFrame == 0:
        thisMonster.HasAttacked = False
    if thisMonster.AttackDelayTime > TimeSpan.FromMilliseconds(750):
        if thisMonster.CurrentFrame == round(thisMonster.FrameCount("attack") / 2, 0) and thisMonster.HasAttacked != True:
            if thisMonster.GetAttackVolume().Intersects(level.TPC.BoundingSphere):
                level.TPC.HandleHit(thisMonster.AttackType)
            thisMonster.HasAttacked = True
            thisMonster.AttackDelayTime = TimeSpan.Zero
elif distanceToPlayer < 1500:
    thisMonster.AttackDelayTime = TimeSpan.Zero #Only allow the attackdelaytime to increase when we're next to the player
    if thisMonster.CurrentAnim != "walk": 
        thisMonster.CurrentAnim = "walk"
    if thisMonster.TargetTile != level.TPC.TilePosition:   #We're not targetting the player
        thisMonster.TargetTile = Vector3(level.TPC.TilePosition.X, 0, level.TPC.TilePosition.Z)
else:
    thisMonster.AttackDelayTime = TimeSpan.Zero
    if thisMonster.CurrentAnim != "idle":
        thisMonster.CurrentAnim = "idle"
    thisMonster.TargetTile = thisMonster.TilePosition
thisMonster.AiState.Push("pathfinding")
